import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [
  { path: '/login', sortIndex: '0', component: () => import('@/views/login/index'), hidden: true },
  { path: '/404', sortIndex: '0', redirect: '/', hidden: true },

  {
    path: '/redirect',
    component: Layout,
    sortIndex: 0,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    sortIndex: 100,
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      meta: { title: '首页', icon: 'example' },
      component: () => import('@/views/dashboard/index')
    }]
  },

  {
    path: '/account',
    component: Layout,
    redirect: '/account/setting',
    sortIndex: 900,
    name: 'Account',
    children: [{
      path: 'setting',
      name: 'AccountSetting',
      meta: { title: '账户设置', icon: 'setting' },
      component: () => import('@/views/user/detail'),
      props: (route) => ({ query: route.query.id })
    }]
  }
]

export default new Router({
  mode: 'history', // 后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '/activity',
    component: Layout,
    redirect: '/activity/list',
    name: 'Activity',
    sortIndex: 200,
    meta: { menuCode: 'hd_activity_list' },
    children: [{
      path: 'list',
      name: 'ActivityList',
      meta: { title: '活动列表', icon: 'activity-list' },
      component: () => import('@/views/activity/list')
    }, {
      hidden: true,
      path: 'detail/:id',
      name: 'ActivityDetail',
      meta: { title: '活动详情', icon: 'detail' },
      component: () => import('@/views/activity/detail'),
      props: (route) => ({ query: route.query.verifycode })
    }]
  },

  {
    path: '/credits',
    component: Layout,
    redirect: '/credits/list',
    name: 'Credits',
    sortIndex: 300,
    meta: { menuCode: 'xf_ctrl_list' },
    children: [{
      path: 'list',
      name: 'CreditsIndex',
      meta: { title: '学分管理', icon: 'xuefengl' },
      component: () => import('@/views/credits/list')
    }]
  },

  {
    path: '/education',
    component: Layout,
    redirect: '/education/score',
    name: 'Education',
    meta: { menuCode: 'jw_mark_list' },
    sortIndex: 400,
    children: [{
      path: 'score',
      name: 'EducationScore',
      meta: { title: '教务成绩', icon: 'jiaowu' },
      component: () => import('@/views/education/score')
    }]
  },

  {
    path: '/credit',
    component: Layout,
    redirect: '/credit/detail',
    name: 'Credit',
    sortIndex: 310,
    meta: { menuHiddenCode: 'xf_score_detail' },
    children: [{
      path: 'detail/:id',
      name: 'CreditDetail',
      meta: { title: '学分详情', icon: 'detail' },
      component: () => import('@/views/credits/detail')
    }]
  },

  {
    path: '/user',
    component: Layout,
    name: 'User',
    sortIndex: 600,
    meta: { title: '用户管理', icon: 'yonghuctrl', menuCode: 'user_ctrl' },
    children: [{
      path: 'group',
      name: 'UserGroup',
      meta: { title: '用户组', icon: 'yonghuzu', menuCode: 'user_group_ctrl' },
      component: () => import('@/views/user/group')
    }, {
      path: 'list',
      name: 'UserList',
      meta: { title: '用户', icon: 'yonghulb' },
      component: () => import('@/views/user/list')
    }, {
      path: 'group-detail/:id',
      name: 'UserGroupDetail',
      hidden: true,
      meta: { title: '用户组详情', icon: 'table' },
      component: () => import('@/views/user/groupDetail')
    }]
  },

  { path: '*', sortIndex: 10000, redirect: '/404', hidden: true }
]
